{
 "cells": [
  {
   "cell_type": "code",
   "execution_count": 3,
   "metadata": {},
   "outputs": [
    {
     "ename": "ApiError",
     "evalue": "status_code: 401, body: {'data': None, 'message': 'Invalid API key', 'details': 'Key not found', 'code': 'A12', 'requestID': 'HA9F2L3VUB', 'support': 'If you have questions or need support, please email ops@nixtla.io'}",
     "output_type": "error",
     "traceback": [
      "\u001b[1;31m---------------------------------------------------------------------------\u001b[0m",
      "\u001b[1;31mApiError\u001b[0m                                  Traceback (most recent call last)",
      "\u001b[1;32me:\\论文研究\\Reservoir_Computing\\pyESN\\data\\timeGPT\\future.ipynb Cell 1\u001b[0m line \u001b[0;36m8\n\u001b[0;32m      <a href='vscode-notebook-cell:/e%3A/%E8%AE%BA%E6%96%87%E7%A0%94%E7%A9%B6/Reservoir_Computing/pyESN/data/timeGPT/future.ipynb#W0sZmlsZQ%3D%3D?line=1'>2</a>\u001b[0m \u001b[39mimport\u001b[39;00m \u001b[39mpandas\u001b[39;00m \u001b[39mas\u001b[39;00m \u001b[39mpd\u001b[39;00m\n\u001b[0;32m      <a href='vscode-notebook-cell:/e%3A/%E8%AE%BA%E6%96%87%E7%A0%94%E7%A9%B6/Reservoir_Computing/pyESN/data/timeGPT/future.ipynb#W0sZmlsZQ%3D%3D?line=3'>4</a>\u001b[0m timegpt \u001b[39m=\u001b[39m TimeGPT(\n\u001b[0;32m      <a href='vscode-notebook-cell:/e%3A/%E8%AE%BA%E6%96%87%E7%A0%94%E7%A9%B6/Reservoir_Computing/pyESN/data/timeGPT/future.ipynb#W0sZmlsZQ%3D%3D?line=4'>5</a>\u001b[0m     \u001b[39m# defaults to os.environ.get(\"TIMEGPT_TOKEN\")\u001b[39;00m\n\u001b[0;32m      <a href='vscode-notebook-cell:/e%3A/%E8%AE%BA%E6%96%87%E7%A0%94%E7%A9%B6/Reservoir_Computing/pyESN/data/timeGPT/future.ipynb#W0sZmlsZQ%3D%3D?line=5'>6</a>\u001b[0m     token \u001b[39m=\u001b[39m \u001b[39m'\u001b[39m\u001b[39mmy_token_provided_by_nixtla\u001b[39m\u001b[39m'\u001b[39m\n\u001b[0;32m      <a href='vscode-notebook-cell:/e%3A/%E8%AE%BA%E6%96%87%E7%A0%94%E7%A9%B6/Reservoir_Computing/pyESN/data/timeGPT/future.ipynb#W0sZmlsZQ%3D%3D?line=6'>7</a>\u001b[0m )\n\u001b[1;32m----> <a href='vscode-notebook-cell:/e%3A/%E8%AE%BA%E6%96%87%E7%A0%94%E7%A9%B6/Reservoir_Computing/pyESN/data/timeGPT/future.ipynb#W0sZmlsZQ%3D%3D?line=7'>8</a>\u001b[0m timegpt\u001b[39m.\u001b[39;49mvalidate_token()\n\u001b[0;32m     <a href='vscode-notebook-cell:/e%3A/%E8%AE%BA%E6%96%87%E7%A0%94%E7%A9%B6/Reservoir_Computing/pyESN/data/timeGPT/future.ipynb#W0sZmlsZQ%3D%3D?line=9'>10</a>\u001b[0m df \u001b[39m=\u001b[39m pd\u001b[39m.\u001b[39mread_csv(\u001b[39m'\u001b[39m\u001b[39mhttps://raw.githubusercontent.com/Nixtla/transfer-learning-time-series/main/datasets/air_passengers.csv\u001b[39m\u001b[39m'\u001b[39m)\n\u001b[0;32m     <a href='vscode-notebook-cell:/e%3A/%E8%AE%BA%E6%96%87%E7%A0%94%E7%A9%B6/Reservoir_Computing/pyESN/data/timeGPT/future.ipynb#W0sZmlsZQ%3D%3D?line=10'>11</a>\u001b[0m df\u001b[39m.\u001b[39mhead()\n",
      "File \u001b[1;32m~\\AppData\\Local\\Packages\\PythonSoftwareFoundation.Python.3.11_qbz5n2kfra8p0\\LocalCache\\local-packages\\Python311\\site-packages\\nixtlats\\timegpt.py:727\u001b[0m, in \u001b[0;36m_TimeGPT.validate_token\u001b[1;34m(self, log)\u001b[0m\n\u001b[0;32m    725\u001b[0m \u001b[39mdef\u001b[39;00m \u001b[39mvalidate_token\u001b[39m(\u001b[39mself\u001b[39m, log: \u001b[39mbool\u001b[39m \u001b[39m=\u001b[39m \u001b[39mTrue\u001b[39;00m) \u001b[39m-\u001b[39m\u001b[39m>\u001b[39m \u001b[39mbool\u001b[39m:\n\u001b[0;32m    726\u001b[0m \u001b[39m    \u001b[39m\u001b[39m\"\"\"Returns True if your token is valid.\"\"\"\u001b[39;00m\n\u001b[1;32m--> 727\u001b[0m     validation \u001b[39m=\u001b[39m \u001b[39mself\u001b[39;49m\u001b[39m.\u001b[39;49mclient\u001b[39m.\u001b[39;49mvalidate_token()\n\u001b[0;32m    728\u001b[0m     valid \u001b[39m=\u001b[39m \u001b[39mFalse\u001b[39;00m\n\u001b[0;32m    729\u001b[0m     \u001b[39mif\u001b[39;00m \u001b[39m\"\u001b[39m\u001b[39mmessage\u001b[39m\u001b[39m\"\u001b[39m \u001b[39min\u001b[39;00m validation:\n",
      "File \u001b[1;32m~\\AppData\\Local\\Packages\\PythonSoftwareFoundation.Python.3.11_qbz5n2kfra8p0\\LocalCache\\local-packages\\Python311\\site-packages\\nixtlats\\client.py:421\u001b[0m, in \u001b[0;36mNixtla.validate_token\u001b[1;34m(self)\u001b[0m\n\u001b[0;32m    419\u001b[0m \u001b[39mexcept\u001b[39;00m JSONDecodeError:\n\u001b[0;32m    420\u001b[0m     \u001b[39mraise\u001b[39;00m ApiError(status_code\u001b[39m=\u001b[39m_response\u001b[39m.\u001b[39mstatus_code, body\u001b[39m=\u001b[39m_response\u001b[39m.\u001b[39mtext)\n\u001b[1;32m--> 421\u001b[0m \u001b[39mraise\u001b[39;00m ApiError(status_code\u001b[39m=\u001b[39m_response\u001b[39m.\u001b[39mstatus_code, body\u001b[39m=\u001b[39m_response_json)\n",
      "\u001b[1;31mApiError\u001b[0m: status_code: 401, body: {'data': None, 'message': 'Invalid API key', 'details': 'Key not found', 'code': 'A12', 'requestID': 'HA9F2L3VUB', 'support': 'If you have questions or need support, please email ops@nixtla.io'}"
     ]
    }
   ],
   "source": [
    "\n",
    "from nixtlats import TimeGPT\n",
    "import pandas as pd\n",
    "\n",
    "timegpt = TimeGPT(\n",
    "    # defaults to os.environ.get(\"TIMEGPT_TOKEN\")\n",
    "    token = 'my_token_provided_by_nixtla'\n",
    ")\n",
    "timegpt.validate_token()\n",
    "\n",
    "df = pd.read_csv('https://raw.githubusercontent.com/Nixtla/transfer-learning-time-series/main/datasets/air_passengers.csv')\n",
    "df.head()\n",
    "timegpt.plot(df, time_col='timestamp', target_col='value')\n"
   ]
  }
 ],
 "metadata": {
  "kernelspec": {
   "display_name": "Python 3",
   "language": "python",
   "name": "python3"
  },
  "language_info": {
   "codemirror_mode": {
    "name": "ipython",
    "version": 3
   },
   "file_extension": ".py",
   "mimetype": "text/x-python",
   "name": "python",
   "nbconvert_exporter": "python",
   "pygments_lexer": "ipython3",
   "version": "3.11.7"
  }
 },
 "nbformat": 4,
 "nbformat_minor": 2
}
